use crate::error::ApiError;
use axum::extract::Json;
use axum::extract::Path;
use axum::extract::Query;
use axum::extract::{FromRequest, FromRequestParts};
use axum_valid::HasValidate;

#[derive(Debug, Clone, Copy, Default, FromRequestParts)]
#[from_request(via(Query), rejection(ApiError))]
pub struct WrappedQuery<T>(pub T);

impl<T> HasValidate for WrappedQuery<T> {
    type Validate = T;

    fn get_validate(&self) -> &Self::Validate {
        &self.0
    }
}

#[derive(Debug, Clone, Copy, Default, FromRequestParts)]
#[from_request(via(Path), rejection(ApiError))]
pub struct WrappedPath<T>(pub T);

impl<T> HasValidate for WrappedPath<T> {
    type Validate = T;

    fn get_validate(&self) -> &Self::Validate {
        &self.0
    }
}

#[derive(Debug, Clone, Copy, Default, FromRequest)]
#[from_request(via(Json), rejection(ApiError))]
pub struct WrappedRequestBody<T>(pub T);


impl<T> HasValidate for WrappedRequestBody<T> {
    type Validate = T;

    fn get_validate(&self) -> &Self::Validate {
        &self.0
    }
}
